package com.briup.day13;

import java.util.Objects;

public class Test_Object {
    public static void main(String[] args) {
        Test_Object t1 = new Test_Object();
//        获取引用变量对应的字节码对象
        System.out.println(t1.getClass());
    }
    public static void main02(String[] args) {
        String s1 = "NB";
        String s2 = "Ma";
        System.out.println(s1.hashCode());
        System.out.println(s2.hashCode());
        System.out.println(s1.hashCode() == s2.hashCode()); //true
        System.out.println(s1.equals(s2)); //false
    }

    public static void main01(String[] args) {
        Stu stu = new Stu("tom", 20);
        Stu stu1 = new Stu("tom", 20);
        System.out.println(stu == stu1);
        System.out.println(stu1.equals(stu));

    }
}

class Stu {
    private String name;
    private int age;

    public Stu(String name, int age) {
        this.name = name;
        this.age = age;
    }

    public Stu() {

    }

    @Override
    public boolean equals(Object o) {
        if (!(o instanceof Stu))
            return false;
        Stu stu = (Stu) o;
//        int是基本数据类型 String是引用数据类型
        return age == stu.age && Objects.equals(name, stu.name);
    }

    @Override
    public int hashCode() {
        return Objects.hash(name, age);
    }
}
